import multer from 'multer';
import path from 'path';
import mkdirp from 'mkdirp'
// 文件夹名称
type Folder = "lunbotu" | "icon" | "miniswiper" | "product" | "productdateils"
export default  {
  multerFun(time:string,folder:Folder){
    
    const storage = multer.diskStorage({
        destination: async (req,file,cd)=>{
            // const time = dayjs().format("YYYY_MM_DD");
            // lunbotu 
            const dir = path.join(__dirname,"../public/uploadfile/"+folder,time);
            await mkdirp(dir);
            cd(null,dir);
        },
        filename:(req,file,cd)=>{
            cd(null,Date.now().toString() + path.extname(file.originalname))
        }
    })
    const upload = multer({storage})
    return upload;
  },
  randomTime(){
    return new Date().getTime();
  }
}
